package com.ocean.productDict.service.impl;

import java.util.*;

import com.ocean.common.core.domain.entity.SysUser;
import com.ocean.common.utils.ShiroUtils;
import com.ocean.common.utils.uuid.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ocean.productDict.mapper.OModeMapper;
import com.ocean.productDict.domain.OMode;
import com.ocean.productDict.service.IOModeService;
import com.ocean.common.core.text.Convert;

/**
 * 模式维护Service业务层处理
 *
 * @author ocean
 * @date 2023-01-04
 */
@Service
public class OModeServiceImpl implements IOModeService
{
    @Autowired
    private OModeMapper oModeMapper;

    /**
     * 查询模式维护
     *
     * @param id 模式维护主键
     * @return 模式维护
     */
    @Override
    public OMode selectOModeById(String id)
    {
        return oModeMapper.selectOModeById(id);
    }

    /**
     * 查询模式维护列表
     *
     * @param oMode 模式维护
     * @return 模式维护
     */
    @Override
    public List<OMode> selectOModeList(OMode oMode)
    {
        return oModeMapper.selectOModeList(oMode);
    }

    /**
     * 新增模式维护
     *
     * @param oMode 模式维护
     * @return 结果
     */
    @Override
    public int insertOMode(OMode oMode)
    {
        oMode.setId(IdUtils.simpleUUID());
        SysUser sysUser = ShiroUtils.getSysUser();
        oMode.setCreateName(sysUser.getUserName());
        oMode.setCreateBy(sysUser.getLoginName());
        oMode.setCreateDate(new Date());
        oMode.setDepartId(sysUser.getDeptId().toString());
        return oModeMapper.insertOMode(oMode);
    }

    /**
     * 修改模式维护
     *
     * @param oMode 模式维护
     * @return 结果
     */
    @Override
    public int updateOMode(OMode oMode)
    {
        SysUser sysUser = ShiroUtils.getSysUser();
        oMode.setUpdateName(sysUser.getUserName());
        oMode.setUpdateBy(sysUser.getLoginName());
        oMode.setUpdateDate(new Date());
        return oModeMapper.updateOMode(oMode);
    }

    /**
     * 批量删除模式维护
     *
     * @param ids 需要删除的模式维护主键
     * @return 结果
     */
    @Override
    public int deleteOModeByIds(String ids)
    {
        return oModeMapper.deleteOModeByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除模式维护信息
     *
     * @param id 模式维护主键
     * @return 结果
     */
    @Override
    public int deleteOModeById(String id)
    {
        return oModeMapper.deleteOModeById(id);
    }

    /**
     *  获取所有名称和编号
     * @return 名称和编号的map
     */
    @Override
    public Map<String, List> getNameAndCode() {
        Map<String, List> result = new HashMap<>();
        List<String> names = new ArrayList<>();
        List<String> codes = new ArrayList<>();
        List<OMode> list = oModeMapper.selectOModeList(new OMode());
        for (OMode mode : list) {
            names.add(mode.getModeName());
            codes.add(mode.getModeCode());
        }
        result.put("names",names);result.put("codes",codes);
        return result;
    }

    @Override
    public List<OMode> getAllMode() {
        return oModeMapper.getAllMode();
    }
}
